<!--
 * @Author: wangshuguang
 * @Date: 2022-08-15 15:08:29
 * @LastEditTime: 2022-08-24 15:22:00
 * @LastEditors: wangshuguang
 * @Description: 文章预览
-->

<template>
  <div class="PreviewArticl">
    <div class="maskHead">
      <div class="maskHeadAppPc">
        <div
          v-for="item in wpList"
          :key="item.name"
          :class="active == item.name? 'active':'maskHeadAppPcTXT'"
          @click="selected(item.name)"
        >
          {{ item.name }}
        </div>
      </div>
    </div>
    <!-- pc展示内容 -->
    <div
      v-if="active === 'pc'"
      class="pcBox"
    >
      <div class="maskContent">
        <span class="maskContent-title">{{ form.articleTitle }}</span>
        <div class="AuthorColumn">
          <div class="AuthorColumn-leftBox">
            <img
              class="AuthorColumn-leftBox-img"
              src="../../../../public/static/img-default/user.png"
            >
            <div class="AuthorColumn-leftBox-AuthorBox">
              <span class="AuthorColumn-leftBox-Author">{{ form.authorName }}</span>
              <span class="AuthorColumn-leftBox-timeDate">{{ dayjs().format('YYYY-MM-DD') }}</span>
            </div>
          </div>
          <div class="AuthorColumn-rightBox">
            <span class="browse">0浏览</span>
            <span class="Collection">0收藏</span>
          </div>
        </div>
      </div>
      <div class="maskImageText">
        <div
          v-if="form.type == 'M'"
          class="contentBox"
          v-html="form.content"
        />
        <div v-else-if="form.type == 'P'">
          <div
            v-for="(file, idx) of fileList"
            :key="file"
            class="fileItem"
          >
            <el-image
              class="avatar"
              :src="file"
              fit="contain"
            />
          </div>
        </div>
        <div v-else-if="form.type == 'R'">
          <div
            v-for="file of fileList"
            :key="file"
            class="fileItem"
          >
            <video
              :src="file"
              controls
              style="width:100%; max-height: 500px"
            />
          </div>
        </div>
      </div>
    </div>
    <!-- app展示内容 -->
    <div v-else-if="active === 'app'">
      <div class="appBox">
        <span class="appTitle">{{ form.articleTitle }}</span>
        <div class="AuthorColumn">
          <div class="AuthorColumn-leftBox">
            <img
              class="AuthorColumn-leftBox-img"
              src="../../../../public/static/img-default/user.png"
            >
            <div class="AuthorColumn-leftBox-AuthorBox">
              <span class="AuthorColumn-leftBox-Author">{{ form.authorName }}</span>
              <span class="AuthorColumn-leftBox-timeDate">{{ dayjs().format('YYYY-MM-DD') }}</span>
            </div>
          </div>
          <div class="AuthorColumn-rightBox">
            <span class="browse">0浏览</span>
            <span class="Collection">0收藏</span>
          </div>
        </div>
        <div class="labelBox">
          <template v-for="labelId of form.labelList">
            <span
              v-if="labelObj[labelId]"
              :key="'label'+labelId"
            >
              {{ labelObj[labelId]['labelNm'] }}
            </span>
          </template>
        </div>
        <div class="ImgTxtBox">
          <div
            v-if="form.type == 'M'"
            class="contentBox"
            v-html="form.content"
          />
          <div v-else-if="form.type == 'P'">
            <div
              v-for="(file, idx) of fileList"
              :key="file"
              class="fileItem"
            >
              <el-image
                class="avatar"
                :src="file"
                fit="contain"
              />
            </div>
          </div>
          <div v-else-if="form.type == 'R'">
            <div
              v-for="file of fileList"
              :key="file"
              class="fileItem"
            >
              <video
                :src="file"
                controls
                style="width:100%;max-height: 500px"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  props: {
    form: {},
    fileList: {},
    labelObj: {}
  },
  data() {
    return {
      dayjs,
      active: 'pc',
      wpList: [{ name: 'pc' }, { name: 'app' }]
    }
  },
  methods: {
    selected(name) {
      this.active = name
      console.log(name)
    }
  }
}
</script>

<style lang="scss" scoped>
.PreviewArticl {
  background: #F3F5F7;
  padding-bottom: 50px;
  .maskHead {
    width: 100%;
    height: 50px;
    justify-content: center;
    display: flex;
    margin-bottom: 50px;

    .maskHeadAppPc {
      display: flex;
      align-items: center;
      .maskHeadAppPcTXT {
        width: 150px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        color: #000000;
        background-color: #ffffff;
        border-radius: 5px;
      }
      .active {
        border: 1px solid #ffffff;
        color: #000000;
        width: 150px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        border-radius: 5px;
        background-color: #02a7f0;
      }
    }
  }
  .contentBox{
    img{
      width: auto;
    }
  }
  .pcBox {
    overflow: auto;
    max-width: 1320px;
    margin:  0 auto;
    background-color: #fff;
    border-radius: 8px;
  }
  .maskContent {
    padding: 30px 80px;
    border-bottom: 1px solid #EAEAEA;
    .maskContent-title {
      display: block;
      margin: 0;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #2e2e2e;
    }
    .AuthorColumn {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 20px;
      .AuthorColumn-leftBox {
        display: flex;
        align-items: center;
        .AuthorColumn-leftBox-img {
          width: 50px;
          height: 50px;
          border-radius: 50%;
        }
        .AuthorColumn-leftBox-AuthorBox {
          display: flex;
          flex-direction: column;
          margin-left: 20px;
          .AuthorColumn-leftBox-timeDate {
            margin-top: 10px;
          }
        }
      }
      .AuthorColumn-rightBox {
        margin-top: 20px;
        .browse {
          margin-right: 20px;
        }
      }
    }
  }
  .maskImageText {
      margin: 0 auto;
      width: 781px;
      overflow: auto;
    .maskImageText-img {
      // width: 500px;
      // height: 200px;
      // margin: 0 auto;
    }
    .maskImageText-txt {
      font-size: 16px;
    }
  }
  .appBox {
    background-color: #fff;
    width: 400px;
    border: 1px solid #000000;
    margin: 20px auto auto auto;
    padding: 10px 20px;
    border-radius: 15px;
    overflow: auto;
    .appTitle {
      font-size: 18px;
      font-weight: 550;
    }
    .AuthorColumn {
      display: flex;
      justify-content: space-between;
      .AuthorColumn-leftBox {
        display: flex;
        align-items: center;
        margin-top: 20px;
        .AuthorColumn-leftBox-img {
          width: 35px;
          height: 35px;
          border-radius: 50%;
        }
        .AuthorColumn-leftBox-AuthorBox {
          display: flex;
          flex-direction: column;
          margin-left: 10px;
          .AuthorColumn-leftBox-timeDate {
            margin-top: 5px;
          }
        }
      }
      .AuthorColumn-rightBox {
        margin-top: 20px;
        .browse {
          margin-right: 20px;
        }
      }
    }
    .labelBox {
      margin-top: 10px;
      span {
        background: #f3f3f3;
        border-radius: 20px;
        padding: 5px 10px;
        margin-right: 5px;
      }
    }
    .ImgTxtBox {
      margin-top: 20px;
      overflow: auto;
      .ImgTxtBox-img {
        width: 100%;
        height: 200px;
      }
      .ImgTxtBox-txt {
        margin-top: 20px;
      }
    }
  }
}
</style>
